<?php
namespace app\index\controller;
use \think\Controller;
use \think\Db;
class Sign extends Controller
{
    public function sign()
    {
        $data = Db::table('sign')->where(['uid'=>session('uid'),'date'=>date('Y-m-d')])->find();
        
        if ($data) {
        	return ['error'=>1,'info'=>'请不要重复签到'];
        }else{
        	$yesterday = Db::table('sign')->where(['uid'=>session('uid'),'date'=>date('Y-m-d',strtotime('-1 days'))])->find();

        	if ($yesterday) {
        		$insertData['cn'] = $yesterday['cn']+1;
        	}else{
        		$insertData['cn'] = 1;
        	}
        	$insertData['stime'] = time();
        	$insertData['uid'] = session('uid');
        	$insertData['date'] = date('Y-m-d');
        	$res = Db::table('sign')->insert($insertData);

        	if ($res) {
        		return ['error'=>0,'info'=>'签到成功','url'=>url('index/index/index')];
        	}else{
        		return ['error'=>1,'info'=>'签到失败'];
        	}
        }
    }

    public function signList(){
        // $data = Db::table('sign')
        // ->
        return $this->fetch('index',[]);
    }
}
?>